import urlConfig from './config.js'

const request = {}
const headers = {}

request.globalRequest = (url, method, params = {}) => {
	headers['token'] = "";
	headers['user-info'] = "";
	switch (method) {
		case "GET":
			headers['Content-Type'] = "application/x-www-form-urlencoded";
			break;
		default:
			headers['Content-Type'] = "application/json;charset=UTF-8";
			break;
	}
	return uni.request({
		url: urlConfig + url,
		method,
		data: params,
		dataType: 'json',
		header: headers
	}).then(res => {
		if (res[1].statusCode && res[1].statusCode == 200) {
			return res[1]
		} else {
			throw res[1].data
		}
	}).catch(parmas => {
		uni.showToast({
			title: parmas.message,
			icon: 'none'
		})
		return Promise.reject(parmas)
	})
}

export default request